package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingLevelController
 * @Author baohua
 * @Date 2024-07-08
 */

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级管理")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    @ApiOperation("查询所有护理等级")
    @GetMapping("/listAll")
    public ResponseResult getAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelService.getAll();
        return ResponseResult.success(nursingLevelVoList);
    }

    @ApiOperation("新增护理等级")
    @PostMapping("/insert")
    public ResponseResult add(
            @ApiParam(value = "护理等级数据传输对象", required = true)
            @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.add(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("分页查询护理等级列表")
    @GetMapping("/listByPage")
    public ResponseResult<NursingLevelVo> listByPage(
            @ApiParam(value = "护理等级名称") String name,
            @ApiParam(value = "状态: 0-禁用, 1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        PageResponse<NursingLevelVo> nursingLevelVoInfo = nursingLevelService.listByPage(name, status, pageNum, pageSize);
        return ResponseResult.success(nursingLevelVoInfo);
    }

    @ApiOperation("根据id查询护理等级数据")
    @GetMapping("/{id}")
    public ResponseResult<NursingLevelVo> getById(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable("id") long id
    ) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    @ApiOperation("修改护理等级")
    @PutMapping("/update")
    public ResponseResult update(
            @ApiParam(value = "请求参数dto类型", required = true)
            @RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    @ApiOperation("删除护理等级")
    @DeleteMapping("/delete/{id}")
    public ResponseResult delete(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable("id") Long id
    ) {
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }

    @ApiOperation("启用禁用")
    @PutMapping("/{id}/status/{status}")
    public ResponseResult modifyStatus(
            @ApiParam(value = "护理等级id", required = true)
            @PathVariable("id") Long id,
            @ApiParam(value = "状态: 0-禁用, 1-启用")
            @PathVariable("status") Integer status
    ) {
        nursingLevelService.modifyStatus(id, status);
        return ResponseResult.success();
    }
}
